<html>
<head>
	<title>Survey</title>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
	<meta name="format-detection" content="telephone=no" />
	
	<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<form action="" method="post">
<table>
<tr>
	<td>Company Name:</td><td><input type="text" name="name" /></td>
</tr>
<tr>
	<td>Sector:</td><td><input type="text" name="sector" /></td>
</tr>
<tr>
	<td>Subsector</td><td><input type="text" name="subsector" /></td>
</tr>
<tr>
	<td>Company Type:</td><td><input type="text" name="type" /></td>
</tr>
<tr>
	<td>Street Address:</td><td><input type="text" name="address" /></td>
</tr>
<tr>
	<td>City:</td><td><input type="text" name="city" /></td>
</tr>
<tr>
<td>State:</td><td>
<?php include 'state.php';
	echo '<select name="state">';
	foreach($states as $k=>$s) {
		echo '<option value="'.$k.'">'.$s.'</option>';
	}
	echo '</select>';
?></td></tr>
<tr>
<td>Zipcode:</td><td><input type="text" name="zipcode" /></td>
</tr>
<tr>
<td>Phone:</td><td><input type="text" name="phone" /></td>
</tr>
<tr>
<td>Note:</td><td><input type="text" name="note" /></td>
</tr>
</table>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
<?php 
include 'config.php';
if (isset($_POST['submit'])) {
	$conn = mysql_connect($host, $user, $password) or die(mysql_error());
	mysql_select_db("mweb_survey");
	
	$name = $_POST['name'];
	$type = $_POST['type'];
	$sector = $_POST['sector'];
	$subsector = $_POST['subsector'];
	$address = $_POST['address'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$zipcode = $_POST['zipcode'];
	$phone = $_POST['phone'];
	$note = $_POST['note'];
	
	$sql_max = "SELECT MAX(CompID) AS comp_id FROM company";
	$result_max = mysql_query($sql_max, $conn) or die(mysql_error());
	$row_max = mysql_fetch_assoc($result_max);
	// echo print_r($row_max);
	$max_cid = $row_max['comp_id'];
	
	$comp_id = $max_cid + 1;
	
	$sql = "INSERT INTO company VALUES ('$comp_id', '$name', '$type', '$address', '$city', '$state', '$zipcode', '$phone', '$note', '$sector', '$subsector')";
	mysql_query($sql, $conn) or die(mysql_error());
	
	header ('location: index.php');
}
?>